def PrimeNumber(b):
    d = 0
    if b == 1:
        return  False
    for i in range(2, b):
        if b % i == 0:
            d = d + 1
    if d == 0:
        return True
a = int(input())
if len(str(a)) > 4 or len(str(a)) < 4 or a <= 0:
    print(0)
    exit()
if a == 1:
    print(0)
a = str(a)
b = a[0:4]
b = int(b)
if PrimeNumber(b) == True:
    print(a)
else:
    d = 0
    a = str(a)
    b = a[0:3]
    b = int(b)
    if PrimeNumber(b) == True:
        print(b)
    else:
        d = 0
        a = str(a)
        b = a[1:4]
        b = int(b)
        if PrimeNumber(b) == True:
            print(b)
        else:
            d = 0
            a = str(a)
            b = a[0:1]
            b = int(b)
            if PrimeNumber(b) == True:
                print(b)
            else:
                d = 0
                a = str(a)
                b = a[1:2]
                b = int(b)
                if PrimeNumber(b) == True:
                    print(b)
                else:
                    d = 0
                    a = str(a)
                    b = a[2:3]
                    b = int(b)
                    if PrimeNumber(b) == True:
                        print(b)
                    else:
                        d = 0
                        a = str(a)
                        b = a[0]
                        b = int(b)
                        if PrimeNumber(b) == True:
                            print(b)
                        else:
                            d = 0
                            a = str(a)
                            b = a[1]
                            b = int(b)
                            if PrimeNumber(b) == True:
                                print(b)
                            else:
                                d = 0
                                a = str(a)
                                b = a[2]
                                b = int(b)
                                if PrimeNumber(b) == True:
                                    print(b)
                                else:
                                    d = 0
                                    a = str(a)
                                    b = a[3]
                                    b = int(b)
                                    if PrimeNumber(b) == True:
                                        print(b)
                                    else:
                                        print(0)




